/**
 * @see [description](https://docs.alipay.com/mini/api/ui-feedback)
 * prompt
 * @param title [string] 标题
 * @param message [string] 文本,默认为'请输入内容'
 * @param placeholder [string] 输入框内的提示文案
 * @param align [string] message对齐方式，可用枚举left/center/right，iOS 'center', android 'left'
 * @param okButtonText [string] 确认按钮文字，默认'确定'
 * @param cancelButtonText [string] 确认按钮文字，默认'取消'
 * @example prompt('标题单行','说明当前状态、提示用户解决方案，最好不要超过两行','给朋友留言');
 */

export default function prompt(title?: string, message?: string, placeholder?: string, align?: string, okButtonText?: string, cancelButtonText?: string) {
	const options = {} as {
		title: string;
		message: string;
		placeholder: string;
		align: string;
		okButtonText: string;
		cancelButtonText: string;
	};
	if (title !== undefined) {
		Object.assign(options, {
			title
		});
	}
	if (message !== undefined) {
		Object.assign(options, {
			message
		});
	}
	if (placeholder !== undefined) {
		Object.assign(options, {
			placeholder
		});
	}
	if (align !== undefined) {
		Object.assign(options, {
			align
		});
	}
	if (okButtonText !== undefined) {
		Object.assign(options, {
			okButtonText
		});
	}
	if (cancelButtonText !== undefined) {
		Object.assign(options, {
			cancelButtonText
		});
	}

	return new Promise<{
		msg: string;
		success: boolean
	}>((resolve, _reject) => {
		my.prompt({
			...options,
			success(res: any) {	// 只有用户点击了确定才会走success
				resolve({
					msg: res.inputValue,
					success: true
				});
			},
			fail() {	// 用户点击了取消走fail
				resolve({
					msg: '',
					success: false
				});
			}
		});
	});
}
